package cn.iver.model;

import cn.iver.component.UserDaoInterceptor;
import cn.iver.model.base.BaseBlog;
import cn.ratel.aop.annotation.Enhancer;
import cn.ratel.db.Cache;
import cn.ratel.db.Page;
import cn.ratel.db.Sqls;
import cn.ratel.ioc.annotation.Model;

import java.util.List;

@Model
public class Blog extends BaseBlog<Blog> {
	public static final Blog dao = new Blog();
	public static final int pageSize = 8;
	public static final int sidebarRecommendsCount = 6;

	@Enhancer(UserDaoInterceptor.class)
	@Cache
	public Page<Blog> page(int pageNumber, int type) {
		Sqls sqls = newSql().and("type=?", type).orderBy("id desc");
		return dao.paginate(sqls, pageNumber, pageSize);
	}

	@Cache
	public Blog one(int id) {
		return find(id);
	}

	@Cache
	public List<Blog> hot() {
		Sqls sqls = newSql().orderBy("viewCount desc").limit(0, sidebarRecommendsCount);
		return dao.find(sqls);
	}

}
